<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:auth=""
>
<auth:data uri="/system/dept/list.json"/>
<head>
    <th:block th:include="common/head::noXadmin('选择部门')"/>
    <script type="application/javascript" th:src="@{/static/js/jquery.min.js}"></script>
    <script type="application/javascript" th:src="@{/static/lib/ztree/js/jquery.ztree.all.min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/static/lib/ztree/css/metroStyle/metroStyle.css}"/>
</head>
<body>
<input type="hidden" id="deptId" th:value="${dept?.deptId}"/>
<input type="hidden" id="deptName" th:value="${dept?.deptName}"/>
<ul id="treeBox" class="ztree"></ul>
<script type="application/javascript">
    var setting = {
            async: {
                enable: true,
                type: "get",
                url: "/system/dept/list.json",
                dataFilter: function (treeId, parentNode, responseData) {
                    var data = responseData.data.list;
                    for (var i = 0; i < data.length; i++) {
                        data[i].icon = "";
                        if ($("#deptId").val() == data[i].deptId) {
                            data[i].checked = 1;
                        }
                    }
                    return data;
                }
            },
            check: {
                enable: false,
                chkStyle: "checkbox"
            },
            data: {
                key: {
                    name: "deptName",
                    title: "deptName"
                },
                simpleData: {
                    enable: true,
                    idKey: "deptId",
                    pIdKey: "parentId",
                    rootPId: 0
                }
            }, callback: {
                onClick: function (event, treeId, treeNode) {
                    $("#deptId").val(treeNode.deptId);
                    $("#deptName").val(treeNode.deptName);
                },
                onAsyncSuccess: function (event, treeId, treeNode) {
                    // zTreeObj.expandAll(true);
                    var s = zTreeObj.getNodeByParam("deptId", $("#deptId").val());
                    zTreeObj.selectNode(s);
                }
            }
        },
        zTreeObj = $.fn.zTree.init($("#treeBox"), setting);
</script>

</body>

</html>
